<?php

/******************************************
* File:				lib_mysql.php
* Version:			1.0.1
* Last modified:	25/10/2009
* Last modifier:	Hugo Lavigne
*****************************************/

Function dbconnect()
{
	$connection = @mysql_connect($_SESSION['server'], $_SESSION['user_mysql'], $_SESSION['pass_mysql']);
	if (!$connection)
		return (-1);
	return($connection);
}

Function dbquery($query, $connect="ok")
{
	if($connect == "ok")
	{
		$connection = dbconnect();
		if ($connection == -1)
			return (FALSE);
		$req = mysql_db_query($_SESSION['database'], $query, $connection);
	}
	else
		$req = mysql_db_query($_SESSION['database'], $query, $connect);
	
	if ($connect == "ok")
		mysql_close($connection);
	
	if (!$req)
		return (FALSE);
	return ($req);
}

Function create_mysql_id($table, $id, $connect="ok")
{
	$req = dbquery("SELECT MAX($id) FROM $table", $connect);
	$id = mysql_result($req, 0, "MAX($id)");
	$id = $id + 1;
	return ($id);
}

Function get_last_id($table, $id, $connect="ok")
{
	$req = dbquery("SELECT MAX($id) FROM $table", $connect);
	$id = mysql_result($req, 0, "MAX($id)");
    return ($id);
}

?>